package com.jinke.api.modules.ums.util;


import com.jinke.api.domain.AdminUserDetails;
import com.jinke.api.modules.ums.model.UmsAdmin;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserUtil {

    public static ThreadLocal<UmsAdmin> UserInfoThreadLocal = new ThreadLocal<>();

    /**
     * 获取当前用户信息
     *
     * @return UserInfoBO
     */
    public static UmsAdmin getUserInfo() {
        AdminUserDetails umsAdmin1 = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return umsAdmin1.getUmsAdmin();
    }

    /**
     * 设置当前用户信息
     *
     * @return UserInfoBO
     */
    public static void setUserInfo(UmsAdmin userInfo) {
        UserInfoThreadLocal.set(userInfo);
    }

    /**
     * 清除当前用户信息
     *
     * @return UserInfoBO
     */
    public static void cleanUserInfo() {
        UserInfoThreadLocal.remove();
    }
}
